package com.cuit.controller.book;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cuit.mapper.BookMapper;
import com.cuit.mapper.UserMapper;
import com.cuit.pojo.Book;
import com.cuit.pojo.User;
import com.cuit.result.R;
import com.cuit.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.List;

@CrossOrigin
@Api(tags = "用户个人管理")
@RestController
@RequestMapping("/personD")
public class personOneDetailController {
    @Resource
    private UserMapper userMapper;
    @Resource
    private FileService fileService;
    @Resource
    private BookMapper bookMapper;
    @GetMapping("/getUserD/{uId}")
    @ApiOperation("获取用户信息")
     public R getUserD(@PathVariable Integer uId){
        User user = userMapper.selectById(uId);
        user.setAvatar(fileService.allPath(user.getAvatar()));
        return R.ok().data("userD",user);
    }
    @GetMapping("/getUserBook/{uId}")
    @ApiOperation("用户商品")
    public R getUserBookD(@PathVariable Integer uId){
        QueryWrapper<Book> queryWrapper =new QueryWrapper<>();
         queryWrapper.eq("userid", uId);
        List<Book> books = bookMapper.selectList(queryWrapper);
        books.forEach(book->{
            book.setBookimg(fileService.allPath(book.getBookimg()));
        });
        return R.ok().data("bookD",books);
    }
}
